package com.blunka.framework.client.utils;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;

import javax.swing.JOptionPane;

import com.blunka.framework.client.constants.DesignConstant;
import com.blunka.framework.client.constants.InitDesignConfig;

public class DesignUtils {

	/**
	 * 获取系统路径
	 *
	 * @return
	 */
	public static String getDir() {
		return System.getProperty("user.dir");
	}

	public static void showMessage(Component parent, String msg, String title, int showType) {
		JOptionPane.showMessageDialog(parent, msg, title, showType);
	}

	public static int showConfirm(Component parent, String msg) {
		return JOptionPane.showConfirmDialog(parent, msg, "系统提示", 0);
	}
	
	/**
	 * 显示提交业务模型确认框
	 * @param parent
	 * @param msg
	 * @return
	 */
	public static int showSubmitConfirm(Component parent, String msg) {
		Object [] options = {"全部提交","提交业务模型","取消"};
		return JOptionPane.showOptionDialog(parent, msg, "系统提示",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
	}

	public static String showInputDialog(Component parent, String msg, String title, int showType) {
		String message = JOptionPane.showInputDialog(parent, msg, title, showType);
		if (("".equals(message)) || (msg == null)) {
			showMessage(parent, msg, title, showType);
			showInputDialog(parent, msg, title, showType);
		}
		return message;
	}

	/**
	 * 获取系统当前日期
	 * @return
	 */
	public static String getCurrentTime(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		return df.format(new Date());
	}
	
    /**
    *
    * @方法没描述：获取唯一序列
    * @author xq
    * @return
    */
   public static final String getRandom(){
   	String random = UUID.randomUUID().toString();
   	return random.replace("-", "").toUpperCase();
   }
   /**
    * 判断是否存在sql关键字
    * @param keyword
    * @return true:存在关键字,false:不存在关键字
    */
   public static boolean isSqlKeyWord(String keyword) {
	   if(InitDesignConfig.getDBType().equals(InitDesignConfig.MYSQL)) {
		   return isMySqlKeyWord(keyword);
	   }else if(InitDesignConfig.getDBType().equals(InitDesignConfig.MSSQL)) {
		   return isMSSQLKeyWord(keyword);
	   }else if(InitDesignConfig.getDBType().equals(InitDesignConfig.ORACLE)) {
		   return isOracleKeyWord(keyword);
	   }
	   return false;
   }
   /**
    * 判断是否为mysql关键字
    * @param keyword
    * @return
    */
   public static boolean isMySqlKeyWord(String keyword) {
	   int index = Arrays.binarySearch(DesignConstant.MYSQL_KEYWORD, keyword);
	   if(index>0) {
		   return true;
	   }
	   return false;
   }
   
   public static boolean isMSSQLKeyWord(String keyword) {
	   int index = Arrays.binarySearch(DesignConstant.MYSQL_KEYWORD, keyword);
	   if(index>0) {
		   return true;
	   }
	   return false;
   }
   
   public static boolean isOracleKeyWord(String keyword) {
	   int index = Arrays.binarySearch(DesignConstant.MYSQL_KEYWORD, keyword);
	   if(index>0) {
		   return true;
	   }
	   return false;
   }
}
